<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Result of your Registration</title>
</head>
<body>
	<% 
		String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
		String connectionURL = "jdbc:odbc:bookstore";
		String sqlQuery = "select username from account";
		Class.forName(driverName).newInstance();
		Connection con = DriverManager.getConnection(connectionURL);
		Statement statement = con.createStatement();
		ResultSet rs = statement.executeQuery(sqlQuery);
		//ResultSetMetaData rsmd = rs.getMetaData();
		//int columnCount = rsmd.getColumnCount();
		String username = request.getParameter("user");
		String password = request.getParameter("pass");
		boolean flag = true;
		while (rs.next()) {
			if (username.equals(rs.getString(1))) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			try {
				sqlQuery = "insert into account values ('" + username + "', '" + password + "')";
				statement.executeQuery(sqlQuery);
			}
			catch (Exception ex) {
				//do nothing
			}
	%>
	<p>
		You have registered successfully. Welcome to our Website. Good luck to you!
	</p>
	<p>
		Please <a href="index.jsp"> click here </a> to return the Index Page. 
	</p>
	<%
		}
		else {
	%>
	<p>
		Your registration have been failed. This username is existing in our Database.
	</p>
	 <p>
		Please <a href="register.jsp"> click here </a> to return the Registration Page. 
	</p>
	<% 
		}
	%>
</body>
</html>